package com.tcs.web.controller.proxypoll;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Lists;
import com.tcs.model.ipdata.IpDataBean;
import com.tcs.model.ipdata.IpDataResultBean;
import com.tcs.server.ipdata.IpDataService;

@RestController
@RequestMapping(value="/proxyPollController")
public class ProxyPollController {

	private final Logger logger = LoggerFactory.getLogger(ProxyPollController.class);
	
	@Resource(name="ipDataService")
	private IpDataService ipDataService;
	
	@RequestMapping(value="/queryAllIp", method=RequestMethod.GET)
	@ResponseBody
	public List<IpDataBean> queryAllIp(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
		IpDataBean ipDataBean = new IpDataBean();
		ipDataBean.setPageNum(pageNum);
		ipDataBean.setPageSize(pageSize);
		List<IpDataBean> resultList = ipDataService.queyListByParams(ipDataBean);
		logger.info("ipDataBean: {} , resultList : {} " , ipDataBean , resultList);
		return resultList;
	}
	
	@RequestMapping(value="/queryPageIpList/{pageNum}", method=RequestMethod.GET)
	@ResponseBody
	public List<IpDataResultBean> queryPageIpList(@PathVariable Integer pageNum) {
		IpDataBean ipDataBean = new IpDataBean();
		ipDataBean.setPageNum(pageNum);
		ipDataBean.setPageSize(10);
		List<IpDataBean> resultList = ipDataService.queyListByParams(ipDataBean);
		List<IpDataResultBean> resultBean = Lists.newArrayList();
		for (IpDataBean tempIpDataBean : resultList) {
			resultBean.add(new IpDataResultBean(tempIpDataBean.getIp(),tempIpDataBean.getPort()));
		}
		logger.info("ipDataBean: {} , resultBean : {} " , ipDataBean , resultBean);
		return resultBean;
	}
	
	
	@RequestMapping(value="/queryAllIp1", method=RequestMethod.GET)
	@ResponseBody
	public List<IpDataBean> queryAllIp() {
		IpDataBean ipDataBean = new IpDataBean();
//		ipDataBean.setPageNum(pageNum);
//		ipDataBean.setPageSize(pageSize);
		ipDataBean.setPageNum(10);
		ipDataBean.setPageSize(1);
		List<IpDataBean> resultList = ipDataService.queyListByParams(ipDataBean);
		logger.info("ipDataBean: {} , resultList : {} " , ipDataBean , resultList);
		return resultList;
	}
}